home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / progjour / 1991 / 02 / monoscrn.asm < prev    next >
Assembly Source File  |  1991-01-09  |  15KB  |  333 lines

  1. ;*******************************************************************************
  2. ;|                                                                             |
  3. ;|      Module:         Monochrome Screen access from Windows 3.0              |
  4. ;|                                                                             |
  5. ;|      Description:    This module demonstrates how to access memory mapped   |
  6. ;|                      devices within the Windows environment.                |
  7. ;|                                                                             |
  8. ;|      Author:         Chris Schwartz  (c) 10/25/90                           |
  9. ;|                                                                             |
  10. ;*******************************************************************************
  11.  
  12.                 .MODEL SMALL  
  13.                 .286
  14.  
  15.                 PUBLIC  DllInit                 ;dll entry point
  16.                 PUBLIC  WEP                     ;dll exit point
  17.  
  18.                 PUBLIC  VioInit
  19.                 PUBLIC  VioWrtStrAttr
  20.                 PUBLIC  VioMovePointer
  21.                 PUBLIC  VioShowPointer
  22.                 PUBLIC  DpmActiveMode
  23.                 PUBLIC  DpmSelectorFromSegment
  24.  
  25. extrn           __B000H:ABS
  26.  
  27.                 .DATA
  28.  
  29. bogusData       dw      8 DUP(0)        ;just to keep windows from wigging out
  30. wVideoSeg       dw      0
  31. iShowPtrLevel   dw      0               ;initially dont display pointer
  32. iRow            dw      0
  33. iCol            dw      0
  34. iOldAttr        dw      0
  35.  
  36.                 .CODE
  37. ;*******************************************************************************
  38. ;|                                                                             |
  39. ;|      FAR PASCAL Calling Convention                                          |
  40. ;|                                                                             |
  41. ;|      BOOL DllInit(VOID); - Dll entry point, called by windows during loading|
  42. ;|                                                                             |
  43. ;|      Entry Values:   DS = Library Data Segment       ES = Command Line Sel  |
  44. ;|                      DI = Module Handle              SI = Command Line Off  |
  45. ;|                      CX = Local Heap Size                                   |
  46. ;|                                                                             |
  47. ;|      Return Values:  AX  = 0 Failed, don't load                             |
  48. ;|                      AX != 0 Success, load this puppy.                      |
  49. ;|                                                                             |
  50. ;*******************************************************************************
  51. ;------------------------------------------------------------------------------- 
  52. DllInit         PROC    FAR
  53.                 mov     ax, 1           ;load this puppy
  54.                 ret
  55. DllInit         ENDP
  56.  
  57. ;*******************************************************************************
  58. ;|                                                                             |
  59. ;|      FAR PASCAL Calling Convention                                          |
  60. ;|                                                                             |
  61. ;|      BOOL WEP(WORD wExitMode); - Dll exit point                             |
  62. ;|                                                                             |
  63. ;|      Return Values:  AX  = 0 Failed Cleanup                                 |
  64. ;|                      AX != 0 Success                                        |
  65. ;|                                                                             |
  66. ;*******************************************************************************
  67. ;------------------------------------------------------------------------------- 
  68. WEP             PROC    FAR
  69.                 mov     ax, 1           ;goodbye
  70.                 ret     2
  71. WEP             ENDP
  72.  
  73. ;*******************************************************************************
  74. ;|                                                                             |
  75. ;|      FAR PASCAL Calling Convention                                          |
  76. ;|                                                                             |
  77. ;|      BOOL DpmActiveMode(VOID);                                              |
  78. ;|                                                                             |
  79. ;|      Return Values:  AX  = 0 Protected Mode under DPMI                      |
  80. ;|                      AX != 0 Real mode, or not under DPMI                   |
  81. ;|                                                                             |
  82. ;*******************************************************************************
  83. ;------------------------------------------------------------------------------- 
  84. DpmActiveMode   PROC    FAR
  85.                 mov     ax, 1686h       ;DPMI Mode Detection Op Code
  86.                 int     2Fh             ;only changes the AX register
  87.                 ret
  88. DpmActiveMode   ENDP
  89.  
  90. ;*******************************************************************************
  91. ;|                                                                             |
  92. ;|      FAR PASCAL Calling Convention                                          |
  93. ;|                                                                             |
  94. ;|      WORD DpmSelectorFromSegment(WORD);                                     |
  95. ;|                                                                             |
  96. ;|      Return Value:  AX = 0 Then function failed, else we have a selector.   |
  97. ;|                                                                             |
  98. ;*******************************************************************************
  99. ;-------------- Formal Parameters ---------------------------------------------- 
  100. wRealSegment    equ     [bp+06]
  101. ;------------------------------------------------------------------------------- 
  102. DpmSelectorFromSegment  PROC    FAR
  103.                 push    bp
  104.                 mov     bp, sp
  105.  
  106.                 mov     ax, 02h
  107.                 mov     bx, wRealSegment
  108.                 int     31h
  109.                 jnc     DpmSFSExit              ;return protected mode selector
  110.  
  111.                 xor     ax, ax                  ;return error code
  112. DpmSFSExit:
  113.                 pop     bp
  114.                 ret     2
  115. DpmSelectorFromSegment  ENDP
  116.  
  117. ;*******************************************************************************
  118. ;|                                                                             |
  119. ;|      FAR PASCAL Calling Convention                                          |
  120. ;|                                                                             |
  121. ;|      VOID VioInit(VOID);                                                    |
  122. ;|                                                                             |
  123. ;*******************************************************************************
  124. ;------------------------------------------------------------------------------- 
  125. VioInit         PROC    FAR
  126.                 push    ds
  127.                 mov     ax, DGROUP
  128.                 mov     ds, ax                  ;fixup the dll's data segment
  129.  
  130.                 mov     ax, __B000H
  131.                 mov     wVideoSeg, ax
  132. VioInitExit:
  133.                 pop     ds
  134.                 ret
  135. VioInit         ENDP
  136.  
  137. ;*******************************************************************************
  138. ;|      AX = row        DX = col    Return: DX:AX                              |
  139. ;*******************************************************************************
  140. ScreenOffset    PROC    NEAR
  141.                 mov     bx, ax
  142.                 mov     cx, 6
  143.                 shl     ax, cl
  144.                 sub     cx, 2
  145.                 shl     bx, cl
  146.                 add     ax, bx
  147.                 add     ax, dx
  148.                 shl     ax, 1
  149.                 mov     dx, wVideoSeg
  150.                 ret
  151. ScreenOffset    ENDP
  152.  
  153. ;*******************************************************************************
  154. ;|                                                                             |
  155. ;|      FAR PASCAL Calling Convention                                          |
  156. ;|                                                                             |
  157. ;|      VioWrtStrAttr(lpData, wLen, wRow, wCol, lpAttr)                        |
  158. ;|                                                                             |
  159. ;*******************************************************************************
  160. ;-------------- Formal Parameters ---------------------------------------------- 
  161. lpData          equ     [bp+16]
  162. wLen            equ     [bp+14]
  163. wRow            equ     [bp+12]
  164. wCol            equ     [bp+10]
  165. lpAttr          equ     [bp+06]
  166. ;------------------------------------------------------------------------------- 
  167. VioWrtStrAttr   PROC    FAR
  168.                 push    bp
  169.                 mov     bp, sp
  170.                 push    ds
  171.                 mov     ax, DGROUP
  172.                 mov     ds, ax                  ;fixup dll's data segment
  173.                 push    es
  174.                 push    di
  175.                 push    si
  176.  
  177.                 mov     ax, wRow
  178.                 mov     dx, wCol
  179.  
  180.                 call    ScreenOffset            ;returns proper video address
  181.                 or      dx, dx
  182.                 je      VioWrtStrAttrExit
  183.  
  184.                 mov     es, dx
  185.                 mov     di, ax
  186.                 mov     cx, wLen
  187.  
  188.                 lds     si, lpAttr
  189.                 lodsb
  190.                 mov     ah, al
  191.                 lds     si, lpData
  192.  
  193. VioWrtStrAttrLoop:
  194.  
  195.                 lodsb
  196.                 stosw
  197.                 loop    VioWrtStrAttrLoop   ;cook those puppies
  198.  
  199. VioWrtStrAttrExit:
  200.                 pop     si
  201.                 pop     di
  202.                 pop     es
  203.                 pop     ds
  204.                 pop     bp
  205.                 ret     14
  206. VioWrtStrAttr   ENDP
  207.  
  208. ;*******************************************************************************
  209. ;|                                                                             |
  210. ;|      FAR PASCAL Calling Convention                                          |
  211. ;|                                                                             |
  212. ;|      VioMovePointer(wRow, wCol)                                             |
  213. ;|                                                                             |
  214. ;*******************************************************************************
  215. ;-------------- Formal Parameters ---------------------------------------------- 
  216. wRow            equ     [bp+08]
  217. wCol            equ     [bp+06]
  218. ;------------------------------------------------------------------------------- 
  219. VioMovePointer  PROC    FAR
  220.                 push    bp
  221.                 mov     bp, sp
  222.                 push    ds
  223.                 mov     ax, DGROUP
  224.                 mov     ds, ax                  ;fixup dll's data segment
  225.                 push    es
  226.                 push    di
  227.                 push    si
  228.  
  229.                 cmp     iShowPtrLevel, 0
  230.                 jle     VMPJustUpdate
  231.  
  232.                 ;now we need to restore the old attr and update the new location
  233.  
  234.                 mov     ax, iRow
  235.                 mov     dx, iCol
  236.                 call    InternalHidePointer
  237.  
  238.                 mov     ax, wRow
  239.                 mov     dx, wCol
  240.                 xor     si, si
  241.                 call    InternalShowPointer
  242. VMPJustUpdate:
  243.                 mov     ax, wRow                ;update internal values
  244.                 mov     dx, wCol
  245.                 mov     iRow, ax
  246.                 mov     iCol, dx
  247. VioMovePointerExit:
  248.                 pop     si
  249.                 pop     di
  250.                 pop     es
  251.                 pop     ds
  252.                 pop     bp
  253.                 ret     4
  254. VioMovePointer  ENDP
  255.  
  256. ;*******************************************************************************
  257. ;|      AX = row        DX = col                                               |
  258. ;*******************************************************************************
  259. InternalShowPointer     PROC    NEAR
  260.                 call    ScreenOffset
  261.                 mov     es, dx
  262.                 inc     ax
  263.                 mov     di, ax
  264.                 mov     ax, WORD PTR es:[di]
  265.                 mov     iOldAttr, ax
  266.                 rol     al, 4
  267.                 stosb
  268.                 ret
  269. InternalShowPointer     ENDP
  270.  
  271. ;*******************************************************************************
  272. ;|      AX = row        DX = col                                               |
  273. ;*******************************************************************************
  274. InternalHidePointer     PROC    NEAR
  275.                 call    ScreenOffset
  276.                 mov     es, dx
  277.                 inc     ax                      ;move over to attr byte
  278.                 mov     di, ax
  279.                 mov     ax, iOldAttr
  280.                 stosb
  281.                 ret
  282. InternalHidePointer     ENDP
  283.  
  284. ;*******************************************************************************
  285. ;|                                                                             |
  286. ;|      FAR PASCAL Calling Convention                                          |
  287. ;|                                                                             |
  288. ;|      VioShowPointer(bTrueFalse)                                             |
  289. ;|                                                                             |
  290. ;*******************************************************************************
  291. ;-------------- Formal Parameters ---------------------------------------------- 
  292. bTrueFalse      equ     [bp+06]
  293. ;------------------------------------------------------------------------------- 
  294. VioShowPointer  PROC    FAR
  295.                 push    bp
  296.                 mov     bp, sp
  297.                 push    ds
  298.                 mov     ax, DGROUP
  299.                 mov     ds, ax                  ;fixup dll's data segment
  300.                 push    es
  301.                 push    di
  302.                 push    si
  303.  
  304.                 mov     ax, bTrueFalse
  305.                 or      ax, ax
  306.                 je      VSPDecLevel
  307.  
  308.                 inc     iShowPtrLevel
  309.                 cmp     iShowPtrLevel, 0
  310.                 jbe     VioShowPointerExit
  311.  
  312.                 mov     ax, iRow
  313.                 mov     dx, iCol
  314.                 call    InternalShowPointer
  315.                 jmp     SHORT VioShowPointerExit
  316. VSPDecLevel:
  317.                 dec     iShowPtrLevel
  318.                 cmp     iShowPtrLevel, 0
  319.                 jne     VioShowPointerExit
  320.  
  321.                 mov     ax, iRow
  322.                 mov     dx, iCol
  323.                 call    InternalHidePointer
  324. VioShowPointerExit:
  325.                 pop     si
  326.                 pop     di
  327.                 pop     es
  328.                 pop     ds
  329.                 pop     bp
  330.                 ret     2
  331. VioShowPointer  ENDP
  332.                 END     DllInit
  333.